package com.wolfcode.web.controller.minIo.config;

import io.minio.MinioClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "minio")
public class MinIoConfig {
    /**
     * 主机地址, 即我们要存放的服务器目标地址
     */
    private  String endpoint ;

    /**
     * 账号
     */
    private String accessKey ;

    /**
     * 密码
     */
    private String secretKey ;

    /**
     * 存储空间, 即我们要存放的目录
     */
    private  String bucket ;

    private static String sBucket;
    private static String sEndpoint;

    public void setEndpoint(String endpoint) {
        this.endpoint = endpoint;
        MinIoConfig.sEndpoint = endpoint;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public  void setBucket(String bucket) {
        this.bucket = bucket;
        MinIoConfig.sBucket = bucket;
    }

    public String getEndpoint() {
        return this.endpoint;
    }

    public String getBucket() {
        return this.bucket;
    }

    public static String getBucketInfo() {
        return MinIoConfig.sBucket;
    }

    public static String getEndpointInfo() {
        return MinIoConfig.sEndpoint;
    }



    @Bean
    public MinioClient minioClient(){
        return MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
    }

}